//
//  ProductListTableViewCell.m
//  QXShowing
//
//  Created by 王道道 on 2018/5/5.
//  Copyright © 2018年 doll_dream. All rights reserved.
//

#import "ProductListTableViewCell.h"

@implementation ProductListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initView];
    }
    return self;
}

- (void)initView {
    //头像
    self.headImage = [[UIImageView alloc]init];
    self.headImage.image = [UIImage imageNamed:@"home-1"];
    self.headImage.layer.masksToBounds = YES;
    self.headImage.layer.cornerRadius = 5;
    [self.contentView addSubview:self.headImage];
    [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15);
        make.height.width.offset(90);
        make.top.equalTo(self.contentView).offset(15);
    }];
    
    //标题
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.textColor = Text_Color_000000;
    self.nameLabel.text = @"田园小清新长裙";
    self.nameLabel.font = BHFont_Size_15;
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImage);
        make.left.equalTo(self.headImage.mas_right).offset(15);//42
        make.right.equalTo(self.contentView).offset(-90);
    }];
    
    //简介
    self.messageLabel = [[UILabel alloc]init];
    self.messageLabel.textColor = Text_Color_333333;
    self.messageLabel.text = @"柔软型面料较为轻薄、悬垂感好，造型服装轮廓自然舒展。柔软型面料主要包好，好，好，好，好，好，好，好，好，好，好，好，好，好，好，好，好，好，好，";
    self.messageLabel.font = BHFont_Size_12;
    self.messageLabel.numberOfLines = 0;
    [self.contentView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(7);
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-15);
    }];
    
    //删除
    self.deleteBtn = [[UIButton alloc]init];
    [self.deleteBtn setImage:[UIImage imageNamed:@"my-5"] forState:UIControlStateNormal];
    [self.deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.deleteBtn];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.right.equalTo(self.messageLabel.mas_right);
        make.width.offset(30);
        make.height.offset(30);
    }];
    
    //编辑
    self.editBtn = [[UIButton alloc]init];
    [self.editBtn setImage:[UIImage imageNamed:@"my-1"] forState:UIControlStateNormal];
    [self.editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.editBtn];
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.right.equalTo(self.deleteBtn.mas_left).offset(-10);
        make.width.offset(30);
        make.height.offset(30);
    }];
}

- (void)deleteAction:(UIButton *)sender {
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

- (void)editAction:(UIButton *)sender {
    if (self.editBlock) {
        self.editBlock();
    }
}

- (void)setModel:(CompanyProductModel *)model {
    if (![BHSettingUtil dataAndStringIsNull:model]) {
        _model = model;
        if (![BHSettingUtil dataAndStringIsNull:model.pic]) {
            [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", BH_PicPreString, model.pic]] placeholderImage:[UIImage imageNamed:@"home-1"]];
        }
//        self.headImage.image = [BHSettingUtil dataAndStringIsNull:model.pic]?nil:model.pic;
        self.nameLabel.text = [BHSettingUtil dataAndStringIsNull:model.product_name]?@"":model.product_name;
        self.messageLabel.text = [BHSettingUtil dataAndStringIsNull:model.Description]?@"":model.Description;
    }
}

@end
